﻿using Desktop.Controls;
using Desktop.Interfaces;
using Desktop.Library;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace StoryWriter
{
    /// <summary>
    /// Interaction logic for StoryEditor.xaml
    /// </summary>
    public partial class StoryEditor : ActivityBase
    {
        #region Constructors

        public StoryEditor(IWorkspace parent, Story story)
            : base(parent)
        {
            InitializeComponent();
            OriginalStory = story;
            Story = OriginalStory.Clone() as Story;
        }

        public StoryEditor(IWorkspace parent)
            : this(parent, new Story())
        {
        }

        #endregion

        #region Properties

        private Story OriginalStory { get; set; }

        private Story Story
        {
            get
            {
                return DataContext as Story;
            }
            set
            {
                DataContext = value;
            }
        }

        #endregion

        #region Event Handlers

        private void ActivityBase_PrincipalChanged(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void acceptButton_Click(object sender, RoutedEventArgs e)
        {
            if (SessionManager.Instance.StoryList.Contains(OriginalStory))
            {
                SessionManager.Instance.StoryList.Remove(OriginalStory);
            }
            SessionManager.Instance.StoryList.Add(Story);
            Close();
        }

        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void NewChapter_Click(object sender, RoutedEventArgs e)
        {

        }

        private void NewCharacter_Click(object sender, RoutedEventArgs e)
        {

        }

        private void NewNote_Click(object sender, RoutedEventArgs e)
        {

        }

        private void Edit_Click(object sender, RoutedEventArgs e)
        {

        }

        private void Remove_Click(object sender, RoutedEventArgs e)
        {

        }

        #endregion
    }
}